module.exports = (sequelize, Sequelize) => {
  const Tag = sequelize.define('tag', {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    name: {
      type: Sequelize.STRING(50),
      allowNull: false,
      unique: true,
      validate: {
        notEmpty: true,
        len: [2, 50]
      }
    },
    description: {
      type: Sequelize.TEXT,
      allowNull: true
    }
  }, {
    timestamps: true,
    paranoid: true, // 软删除
    indexes: [
      {
        unique: true,
        fields: ['name']
      }
    ]
  });

  return Tag;
};